import { ApiCall } from "tsrpc";
import { ReqJoin_team, ResJoin_team } from "../../../../shared/master/bag/function/PtlJoin_team";
import { player } from "../../../../model/fight/body/player";
import { template } from "../../../../shared/master/MsgAction";
import manage_team from "../../../model/manage/manage_team";
import { logger } from "../../../../model/server/logger";

export default async function (call: ApiCall<ReqJoin_team, ResJoin_team>) {
    call.succ({})
    let user = call.req._player as player;
    let _team = user.get_team();
    if (_team) {
        user.sendMsg(template.default, `您已加入${_team.name},请先退出小队`)
        return;
    }
    let res = user.check_wallet(0, 0, [{ id: call.req.team_id, v: 1 }], false, '加入小队', true);
    if (!res.state) {
        return;
    }
    let now_team = manage_team.join_team(user, call.req.team_id);
    if (!now_team) {
        logger.debug('小队不存在')
        debugger;
        return;
    }
    user.sendMsg(template.default, `加入${now_team.name}成功`)
}